let menu = [{
        "menuname": "商品管理",
        "children": [{
                "sidername": "商品管理",
                "list": [{
                        "title": "商品列表",
                        url: "./html/shangpinguanli/shangpinliebiao.html"
                    },
                    {
                        "title": "新增商品",
                        url: "./html/shangpinguanli/xinzengshangpin1.html"
                    },
                    {
                        "title": "商品评价",
                        url: "./html/shangpinguanli/shangpinpingjia.html"
                    },
                    {
                        "title": "商品回收站",
                        url: "./html/shangpinguanli/shangpinhuishouzhan.html"
                    }
                ]
            },
            {
                "sidername": "商品属性",
                "list": [{
                        "title": "商品分类",
                        url: "./html/shangpinshuxing/shangpinfenlei.html"
                    },
                    {
                        "title": "新增分类",
                        url: "./html/shangpinshuxing/xinznegfenlei.html"
                    },
                    {
                        "title": "商品品牌",
                        url: "./html/shangpinshuxing/shangpinpinpai.html"
                    },
                    {
                        "title": "新增品牌",
                        url: "./html/shangpinshuxing/xinzengpinpai.html"
                    },
                    {
                        "title": "商品规格",
                        url: "./html/shangpinshuxing/shangpinguige.html"
                    }
                ]
            },
        ]
    },
    {
        "menuname": "订单管理",
        "children": [{
                "sidername": "订单管理",
                "list": [{
                        "title": "订单列表",
                        url: "./html/orderform/orderformlist.html"
                    },
                    {
                        "title": "订单设置",
                        url: "./html/orderform/orderformset.html"
                    },
                    {
                        "title": "运单列表",
                        url: "./html/orderform/waybilllist.html"
                    },
                    {
                        "title": "取消原因",
                        url: "./html/orderform/quxiaoyuanyin.html"
                    }
                ]
            },
            {
                "sidername": "退换货管理",
                "list": [{
                        "title": "退货列表",
                        url: "./html/tuihuanhuo/tuihuolist.html"
                    },
                    {
                        "title": "换货列表",
                        url: "./html/huanhuoliebiao/huanhuolist.html"
                    },
                    {
                        "title": "退换货原因",
                        url: "./html/tuihuanhuo/tuihuanyuanyin.html"
                    }
                ]
            },
        ]
    },
    {
        "menuname": "物流管理",
        "children": [{
            "sidername": "物流管理",
            "list": [{
                    "title": "运费模板",
                    url: "./html/wuliuganli/yunfeimoban.html"
                },
                {
                    "title": "新增运费模板",
                    url: "./html/wuliuganli/xinzengmuban.html"
                },
                {
                    "title": "包裹中心",
                    url: "./html/wuliuganli/baoguozhongxin.html"
                },
                {
                    "title": "快递公司",
                    url: "./html/wuliuganli/kuaidigongsi.html"
                },
                {
                    "title": "地址列表",
                    url: "./html/wuliuganli/dizhiliebiao.html"
                },
                {
                    "title": "新增地址",
                    url: "./html/wuliuganli/xinzengdizhi.html"
                }
            ]
        }]
    },
    {
        "menuname": "促销管理",
        "children": [{
                "sidername": "促销管理",
                "list": [{
                        "title": "限时购列表",
                        url: "./html/cuxiaoguanli/cuxiaoguanli.html"
                    },
                    {
                        "title": "新增限时购活动",
                        url: "./html/cuxiaoguanli/xinzengxianshigou.html"
                    },
                    {
                        "title": "优惠券列表",
                        url: "./html/cuxiaoguanli/youhuiquanliebiao.html"
                    },
                    {
                        "title": "新增优惠券",
                        url: "./html/cuxiaoguanli/xinzengyouhuiquan.html"
                    }
                ]
            },
            {
                "sidername": "广告管理",
                "list": [{
                        "title": "广告落地页",
                        url: "./html/guangGaoGuanLi/guangGao_GGluoDi.html"
                    },
                    {
                        "title": "新增落地页",
                        url: ""
                    },
                    {
                        "title": "Banner列表",
                        url: ""
                    },
                    {
                        "title": "新增Banner",
                        url: ""
                    }
                ]
            },
        ]
    },
    {
        "menuname": "文章管理",
        "children": [{
            "sidername": "文章管理",
            "list": [{
                    "title": "文章列表",
                    url: "./html/wenzhangguanli/wenzhangguanlishouye.html"
                },
                {
                    "title": "新增文章",
                    url: "./html/wenzhangguanli/xinzengwenzhang.html"
                },
                {
                    "title": "文章分类",
                    url: "./html/wenzhangguanli/wenzhangfenlei.html"
                },
                {
                    "title": "文章评论列表",
                    url: "./html/wenzhangguanli/wenzhangpinlun.html"
                }
            ]
        }]
    },
    {
        "menuname": "权限管理",
        "children": [{
            "sidername": "权限管理",
            "list": [{
                    "title": "账号管理",
                    url: "./html/quanXianGuanLi/zhangHaoGuanLi.html"
                },
                {
                    "title": "新增账号",
                    url: "./html/quanXianGuanLi/xinZengZhangHu.html"
                },
                {
                    "title": "角色管理",
                    url: "./html/quanXianGuanLi/jueSheGuanLi.html"
                },
                {
                    "title": "新增角色",
                    url: "./html/quanXianGuanLi/xinZengJueShe.html"
                },
                {
                    "title": "功能管理",
                    url: "./html/quanXianGuanLi/gongNengGuanLi.html"
                },
                {
                    "title": "组织管理",
                    url: "./html/quanXianGuanLi/zuZhiGuanLi.html"
                }
            ]
        }]
    },
]

window.onload = function() {
    if (sessionGet('username') == null) {
        $('.modal').modal('toggle')
        $('.modal').on('hidden.bs.modal', function() {
            location.href = './html/login/login.html'
        })
    }
    showmenu(menu, "#header>ul")
    $('#header>ul').on('click', 'li', function() {
        changemenu(this, menu)
    })
    $('#sider').on('click', 'ul>li', function() {
        changesider(this, menu)
    })
    let height = window.innerHeight - 55
    let width = window.innerWidth - 190
    $('#sider').css('height', height + 'px')
    $('#title').css('width', width)
    $('#content>iframe').css('width', width + 'px')
    $('#content').css('height', height - 50 + 'px')
    $('#content>iframe').css('height', height - 50 + 'px')

    $('#reste').click(function() {
        $('#content>iframe').attr('src', $('#content>iframe').attr('src'));
    })
    $('#back').click(function() {
        window.history.back()
    })
    $('#goout').mouseenter(function() {
        $('#goout').css('transform', 'translateY(0)')
    })
    $('#goout').mouseleave(function() {
        $('#goout').css('transform', 'translateY(-200px)')
    })
    $('#header>div:last-child').mouseenter(function() {
        $('#goout').css('transform', 'translateY(0)')
    })
    $('#header>div:last-child').mouseleave(function() {
        $('#goout').css('transform', 'translateY(-200px)')
    })
    $('.mymsg').on('click',function(){
        $('#content>iframe').attr('src','./html/gerenxinxi/wodexinxi.html')
    })
    $('.logout').on('click',function(){
        sessionRemove('username')
        sessionRemove('pwd')
        location.href='./html/login/login.html'
    })
}
window.onresize = function() {
    let height = window.innerHeight - 55
    let width = window.innerWidth - 190
    $('#sider').css('height', height + 'px')
    $('#title').css('width', width)
    $('#content>iframe').css('width', width + 'px')
    $('#content').css('height', height - 50 + 'px')
    $('#content>iframe').css('height', height - 50 + 'px')
}

function showmenu(menulist, location) {
    for (let i = 0; i < menulist.length; i++) {
        if (i == 0) {
            $(location).append(`
                <li class="col-md-1-5 menu">${menulist[i].menuname}</li>
            `)
        } else {
            $(location).append(`
                <li class="col-md-1-5">${menulist[i].menuname}</li>
            `)
        }
    }
    showsider(menulist[0].children, '#sider')
    $('#content>iframe').attr('src', menulist[0].children[0].list[0].url)
}

function showsider(siderlist, location) {
    $(location).html('')
    for (let i = 0; i < siderlist.length; i++) {
        let childrens = ``
        $(location).append(`
            <div>
                <span class="iconfont">&#xe67d;</span>
                <span>${siderlist[i].sidername}</span>
            </div>
        `)
        for (let j = 0; j < siderlist[i].list.length; j++) {
            if (i == 0 && j == 0) {
                childrens += `
                <li class='sideritem'>
                    <span class="iconfont">&#xe6b7;</span>
                    <span>${siderlist[i].list[j].title}</span>
                </li>
            `
            } else {
                childrens += `
                <li>
                    <span class="iconfont">&#xe6b7;</span>
                    <span>${siderlist[i].list[j].title}</span>
                </li>
            `
            }
        }
        $(location).append(`<ul>` + childrens + `</ul>`)
    }
}

function changemenu(el, menulist) {
    for (let i = 0; i < $(el).parent().children().length; i++) {
        $($(el).parent().children()[i]).removeClass('menu');
    }
    $(el).addClass('menu');
    let sider = menulist.filter(item => item.menuname == $(el).text())
    showsider(sider[0].children, '#sider')
    $('#content>iframe').attr('src', sider[0].children[0].list[0].url)
}

function changesider(el, menulist) {
    for (let i = 0; i < $($(el).parent().parent().find('ul')[0]).children().length; i++) {
        $($($(el).parent().parent().find('ul')[0]).children()[i]).removeClass('sideritem');
    }
    for (let i = 0; i < $($(el).parent().parent().find('ul')[1]).children().length; i++) {
        $($($(el).parent().parent().find('ul')[1]).children()[i]).removeClass('sideritem');
    }
    $(el).addClass('sideritem');
    let sider = menulist.filter(item => item.menuname == $(el).parent().parent().find('div:first-child').find('span:last-child').text())
    sider = sider[0].children
    sider = sider.filter(item => item.sidername == $(el).parent().prev().find('span:last-child').text())
    sider = sider[0].list
    sider = sider.filter(item => item.title == $(el).find('span:last-child').text())
    $('#content>iframe').attr('src', sider[0].url)
}